package sk.octopuss.archery.dao.impl;

import java.util.List;

import javax.persistence.Query;

import org.springframework.stereotype.Repository;

import sk.octopuss.archery.dao.AbstractGenericDao;
import sk.octopuss.archery.dao.BrandDao;
import sk.octopuss.archery.domain.Brand;

@Repository
public class BrandDaoImpl extends AbstractGenericDao<Brand> implements BrandDao {

	@Override
	public Brand find(final Long id) {
		final Query query = em.createQuery("Select b FROM Brand b Where b.id ="+id);
		return (Brand)query.getSingleResult();
	}

	@Override
	public List<Brand> findAll() {
		final Query query = em.createQuery("Select b FROM Brand b");
		return query.getResultList();
	}

	@Override
	public long countAll() {
		 return (Long)em.createQuery("SELECT COUNT(b) FROM Brand b").getSingleResult();
	}

	@Override
	public long save(final Brand entity) {
		em.persist(entity);	
		return entity.getId();
		
	}

	@Override
	public void delete(final Brand entity) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public List<Brand> findAllByName(final String name) {
		final Query query = em.createQuery("Select b FROM Brand b Where b.name ="+name);
		return query.getResultList();
	}

	@Override
	public List<Brand> findAllEntries(final int firstResult, final int maxResults) {
		// TODO Auto-generated method stub
		return null;
	}

}
